﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;

namespace OperaThumbnailer
{
	/// <summary>
	/// Description of DialInfo.
	/// </summary>
	public class SpeedDialData
	{
		private List<Dial> dials;
		public List<Dial> Dials { get { return dials; } }
		
		public SpeedDialData(string opThumbDatPath)
		{
			dials = new List<Dial>();
			
			string thumbDat = File.ReadAllText(opThumbDatPath);
			thumbDat = thumbDat.Replace(Convert.ToChar(0x0D), Convert.ToChar(0));
			string[] split = Regex.Split(thumbDat, "...\x01..");
			
			foreach (string dial in split) {
				if (dial.Length > 10) {
					string[] parts = Regex.Split(dial, "\x03..|\x04..");
					dials.Add(new Dial(parts[0], parts[1], parts[2]));
				}
			}
		}
	}
	
	public class Dial
	{
		private string url;
		private string thumbFile;
		private string title;
		public string Url { get { return url; } }
		public string ThumbFile { get { return thumbFile; } }
		public string Title { get { return title; } }
		
		public Dial(string url, string thumbFile, string title)
		{
			this.url = url;
			this.thumbFile = thumbFile;
			this.title = title;
		}
	}
}
